

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CreateGroup extends StatefulWidget {
  CreateGroupWidget createState() => new CreateGroupWidget();
}

class CreateGroupWidget extends State<CreateGroup> {

  TextEditingController textEditingController=new TextEditingController();
  List<String> all=<String>['好友1','好友2','好友3','好友4','好友5','好友6',];
  var name = new Set();
  setWidth(){
    switch(name.length){
      case 0:
        return 1;
        break;
      case 1:
        return 1;
        break;
      case 2:
        return 2;
        break;
      case 3:
        return 3;
        break;
      case 4:
        return 4;
        break;
      case 5:
        return 5;
        break;
      case 6:
        return 6;
        break;
    }
    return 6;
  }
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: Text(
          '创建群聊',
          style: TextStyle(
            fontSize: 25.0,
          ),
        ),
      ),
      body: Column(
        children: <Widget>[
        Expanded(
          flex: 1,
          child:   Row(
            children: <Widget>[
              Expanded(
                flex: setWidth(),
                child: ListView.builder(itemBuilder:(BuildContext context,int position){
                  return Container(
                    padding:EdgeInsets.all(2.0),
                    child: Icon(Icons.person),
                  );
                },
                  itemCount: name.length,
                  scrollDirection: Axis.horizontal,),
              ),
              Expanded(
                flex: 15-setWidth(),
                child: Container(
                  child: TextField(
                    controller: textEditingController,
                    decoration: InputDecoration(
                        border: OutlineInputBorder(
                            borderSide: BorderSide(
                                width: 2.0,
                                color: Colors.white
                            ),
                            borderRadius: BorderRadius.all(Radius.circular(5.0))
                        )
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
          Expanded(
            flex: 8,
            child:  Container(
              child: ListView.builder(itemBuilder: (BuildContext context,int position){
                bool _ischeck = name.contains(all.elementAt(position));
                return ListTile(
                  title: Text(all.elementAt(position)),
                  leading: Icon(Icons.person),
                  trailing: _ischeck
                      ? Icon(
                    Icons.check,
                    color: Colors.red,
                  )
                      : null,
                  onTap: (){
                    if (_ischeck == true) {
                      setState(() {
                        name.remove(all.elementAt(position));
                      });
                    } else {
                      setState(() {
                        name.add(all.elementAt(position));
                      });
                    }
                  },
                );
              },itemCount: all.length,),
            ),
          ),
          Expanded(
            flex: 1,
            child:  Container(
              child: RaisedButton(
                child: Text('创建群聊'),
                onPressed: (){
                  //
                },
              ),
            ) ,
          )
        ],
        )
      );
  }
}
